package org.daidai.abstrusewriting.homepage.hot.adapters;

import android.content.Context;
import android.graphics.Bitmap;
import android.media.Image;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;

import org.daidai.abstrusewriting.homepage.hot.model.FocusImages;

import java.util.List;

/**
 * Created by Administrator on 2016/10/31.
 */

public class HeadPictureAdapter extends PagerAdapter {
    List<FocusImages.SignImage> list;
    Context context;

    public HeadPictureAdapter(Context context, List list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
       return 3000;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(((View) object));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View ret = null;
        if (list.size()>0) {
        ImageView imageView = new ImageView(context);
        int size = list.size();
        Picasso.with(context)
                .load(list.get(position%size).getPic())
                .config(Bitmap.Config.ARGB_8888)
                .into(imageView);
        container.addView(imageView);
        ret = imageView;
        }
        return ret;
    }
}
